package com.zkzx.operation.api.service.truck;

import com.zkzx.common.company.model.CompanyVO;
import com.zkzx.common.truck.model.CompanyTruckVO;
import com.zkzx.common.truck.model.TruckVO;
import com.zkzx.operation.api.client.company.CompanyClient;
import com.zkzx.operation.api.client.truck.TruckClient;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/12/20:10
 * @Description:
 */
@Service
public class TruckService {

    @Autowired
    private TruckClient truckClient;

    @Autowired
    private CompanyClient companyClient;


    public TruckVO getById(Integer id, Integer companyId, Integer userId){
        TruckVO truckVO = truckClient.getById(id,companyId,userId);
        List<CompanyTruckVO> list = companyClient.getByTruckIdCompanyId(id, companyId);
        if (CollectionUtils.isNotEmpty(list)) {
            list.forEach(companyTruck -> {
                CompanyVO companyVO = companyClient.getById(companyTruck.getCompanyId());
                companyTruck.setName(companyVO.getName());
            });
        }
        truckVO.setCompanyTrucks(list);
        return truckVO;
    }
}
